const { handleAdd, handleList } = require('../models/comment')

// 评论 回复
const add = async (ctx, next) => {
    // session 验证
    if (JSON.stringify(ctx.session) === '{}') {
        return ctx.body = {code: 401, data: null, msg: '登录过期'};
    }
    if(ctx.session.role){
        ctx.body = await handleAdd({userId: ctx.session.id, ...ctx.request.body}).catch(err => ctx.body = err);
    }else{
        ctx.body = {code: 401, data: null, msg: '暂无权限'}
    }
}

// 查询
const list = async (ctx, next) => {
    ctx.body = await handleList(ctx.request.query).catch(err => ctx.body = err);
}

module.exports = { add, list }
